package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.DiscountCardMember;
import com.addplus.townmall.server.api.model.town.expand.DiscountCardMemberExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商城用户会员卡记录信息表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface DiscountCardMemberMapper extends BaseAddMapper<DiscountCardMember> {

    @Select("SELECT d.id,d.member_id,m.nick_name,d.discount_card_id,c.`name` as discount_card_name,d.start_date as start,d.end_date as end,d.offer_amount,d.is_ugrade,d.discuount_status,d.source FROM discount_card_member d LEFT JOIN member m ON d.member_id=m.id and m.is_deleted=0 LEFT JOIN discount_card c ON d.discount_card_id=c.id AND c.is_deleted=0 where d.is_deleted=0 ")
    List<DiscountCardMemberExpand> getAllDiscountCardMember(IPage page);
    @Select("SELECT d.id,d.member_id,d.discount_card_id,d.start_date as start,d.end_date as end,d.offer_amount,d.is_ugrade,d.discuount_status,d.source FROM discount_card_member d where d.is_deleted=0 AND d.id=#{id}")
    DiscountCardMemberExpand getDiscountCardMemberById(@Param("id")Integer id);

    @Select("SELECT dcm.*,dc.type as card_type,dc.`name` as discount_card_name " +
            "FROM discount_card_member dcm  " +
            "inner JOIN discount_card dc ON dcm.discount_card_id=dc.id " +
            "where ${ew.sqlSegment} ")
    List<DiscountCardMemberExpand> getDiscountCardMemberWithCard(@Param("ew") Wrapper wrapper);
}
